package vues;

import java.awt.EventQueue;

import javax.swing.JFrame;

import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;

import modele.entites.TypeBot;

import javax.swing.SwingConstants;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.ImageIcon;

import evenements.EcouteurProfilFrame;

import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.Toolkit;
import java.awt.Window.Type;

public class ProfilWindow extends JFrame {

	private JTextField robotName;
	private final JComboBox typeRobot = new JComboBox<TypeBot>(); 
	private IHM ihm;
	private int X, Y;

	public String getRobotName() {
		return robotName.getText();
	}
	
	public TypeBot getTypeRobot(){
		return TypeBot.valueOf(typeRobot.getSelectedItem().toString());
	}
	
	public ProfilWindow(IHM ihm, int X, int Y) {
		setResizable(false);
		this.ihm = ihm;
		this.X = X;
		this.Y = Y;
		initialize();
		this.setVisible(true);
	}

	private void initialize() {
		this.setIconImage(Toolkit.getDefaultToolkit().getImage(ProfilWindow.class.getResource("/vues/robot-haut-urbain.png")));
		this.setTitle("Profil robot");
		this.setBounds(100, 100, 329, 142);
		this.setResizable(false);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.getContentPane().setLayout(null);
		final JLabel lblNewLabel = new JLabel("");
		
		JLabel lblProfil = new JLabel("Profil :");
		lblProfil.setHorizontalAlignment(SwingConstants.RIGHT);
		lblProfil.setBounds(20, 14, 46, 14);
		this.getContentPane().add(lblProfil);
		typeRobot.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent arg0) {
				switch (getTypeRobot())
				{
				case Foret:
					lblNewLabel.setIcon(new ImageIcon(ProfilWindow.class.getResource("/vues/robot-haut-foret.png")));
					break;
				case Amphibie:
					lblNewLabel.setIcon(new ImageIcon(ProfilWindow.class.getResource("/vues/robot-haut-eau.png")));
					break;
				case Urbain:
					lblNewLabel.setIcon(new ImageIcon(ProfilWindow.class.getResource("/vues/robot-haut-urbain.png")));
					break;
				default:
					lblNewLabel.setIcon(new ImageIcon(ProfilWindow.class.getResource("/vues/robot-haut-urbain.png")));
					break;
				}
				
			}
		});
		typeRobot.setModel(new DefaultComboBoxModel(TypeBot.values()));
		typeRobot.setBounds(76, 11, 132, 20);
		this.getContentPane().add(typeRobot);
		
		JLabel lblNom = new JLabel("Nom :");
		lblNom.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNom.setBounds(20, 45, 46, 14);
		this.getContentPane().add(lblNom);
		
		robotName = new JTextField();
		robotName.setBounds(76, 42, 132, 20);
		this.getContentPane().add(robotName);
		robotName.setColumns(10);
		
		JButton btnValider = new JButton("Valider");
		btnValider.addActionListener(new EcouteurProfilFrame(this, this.ihm, this.X, this.Y));
		btnValider.setBounds(20, 73, 89, 23);
		this.getContentPane().add(btnValider);
		
		JButton btnAnnuler = new JButton("Annuler");
		btnAnnuler.addActionListener(new EcouteurProfilFrame(this, this.ihm, this.X, this.Y));
		btnAnnuler.setBounds(119, 73, 89, 23);
		this.getContentPane().add(btnAnnuler);
		
		lblNewLabel.setBounds(237, 18, 52, 69);
		lblNewLabel.setIcon(new ImageIcon(ProfilWindow.class.getResource("/vues/robot-haut-urbain.png")));
		this.getContentPane().add(lblNewLabel);
		
		
	}
}
